package il.ac.technion.cs236700.address_book;

import il.ac.technion.cs236700.utils.Misc;

/**
 * An immutable object that represents an address.
 * 
 */
public class Address
{
   /**
    * Building, flat #, floor, etc.
    */
   public final String building;
   
   /**
    * Name of street
    */
   public final String street;
   
   /**
    * City
    */
   public final String city;
   
   /**
    * Zip code
    */
   public final String zip;
   
   /**
    * Country name
    */
   public final String country;
   
   public Address(String building_, String street_, String city_, String zip_,
      String country_)
   {
      building = building_;
      street = street_;
      city = city_;
      zip = zip_;
      country = country_;
   }
   
   @Override
   public int hashCode()
   {
      return Misc.hash(building, street, city, zip, country);    
   }
   
   @Override
   public boolean equals(Object o)
   {
      Address that = Misc.cast(this, o);
      return that != null && Misc.eq(building, that.building) 
         && Misc.eq(street, that.street)
         && Misc.eq(city, that.city)
         && Misc.eq(zip, that.zip)
         && Misc.eq(country, that.country);
   }
   
   @Override
   public String toString() {
      return (building + " " + street + " " + city + " " + zip + " " + country)
         .trim();
   }
}
